Skip to content

Conversation

nick-Ag
Copy link
Contributor

@nick-Ag nick-Ag commented Jun 25, 2025

This PR supports the rollout of Liquid Templates by adding some stats tracking including tags for which field is triggering the metrics.

Testing

Tested successfully in stage by triggering a Liquid template evaluation in the action tester.
Metrics come through as expected

Screenshot 2025-08-18 at 10 01 56 AM
  • Added unit tests for new functionality
  • Tested end-to-end using the local server
  • [If destination is already live] Tested for backward compatibility of destination. Note: New required fields are a breaking change.
  • [Segmenters] Tested in the staging environment
  • [Segmenters] [If applicable for this change] Tested for regression with Hadron.

Copy link
Contributor

This PR makes changes to mapping-kit. Please ensure that the changes are reflected in the mapping-kit go library as well and link the PR in description.

Copy link

codecov bot commented Jun 26, 2025

Codecov Report

Attention: Patch coverage is 90.96573% with 29 lines in your changes missing coverage. Please review.

Project coverage is 80.06%. Comparing base (a3c4d89) to head (8d0c746).
Report is 28 commits behind head on main.

Files with missing lines Patch % Lines
...destinations/twilio-messaging/sendMessage/utils.ts 60.00% 4 Missing and 2 partials ⚠️
...tions/src/destinations/eagleeye-audiences/index.ts 44.44% 5 Missing ⚠️
...on-actions/src/destinations/attentive/functions.ts 50.00% 1 Missing and 3 partials ⚠️
...ns/amazon-conversions-api/trackConversion/utils.ts 66.66% 1 Missing and 2 partials ⚠️
packages/core/src/mapping-kit/index.ts 91.66% 2 Missing ⚠️
.../destinations/braze-cohorts/syncAudiences/index.ts 92.00% 1 Missing and 1 partial ⚠️
...agleeye-audiences/triggerBehavioralAction/index.ts 33.33% 1 Missing and 1 partial ⚠️
...actions/src/destinations/singlestore/send/utils.ts 92.59% 0 Missing and 2 partials ⚠️
...triggerCanvas/functions/dynamic-field-functions.ts 95.00% 0 Missing and 1 partial ⚠️
...ions/src/destinations/braze/triggerCanvas/index.ts 96.00% 1 Missing ⚠️
... and 1 more
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #3024       +/-   ##
===========================================
+ Coverage   32.57%   80.06%   +47.48%     
===========================================
  Files          14     1186     +1172     
  Lines         703    23877    +23174     
  Branches      119     4860     +4741     
===========================================
+ Hits          229    19116    +18887     
- Misses        474     4055     +3581     
- Partials        0      706      +706     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@nick-Ag nick-Ag changed the title WIP - pipes through statsContext to evaluateLiquid directive function Pipes through statsContext to evaluateLiquid directive function Jul 2, 2025
@nick-Ag nick-Ag marked this pull request as ready for review July 3, 2025 00:06
@nick-Ag nick-Ag requested review from a team as code owners July 3, 2025 00:06
pooyaj
pooyaj previously approved these changes Jul 3, 2025
varadarajan-tw
varadarajan-tw previously approved these changes Jul 3, 2025
silesky
silesky previously approved these changes Jul 3, 2025
@joe-ayoub-segment joe-ayoub-segment dismissed stale reviews from silesky and varadarajan-tw via a1a0b87 July 8, 2025 10:27
Copy link
Contributor

@joe-ayoub-segment joe-ayoub-segment left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved conflict - so approving after this only. PR was already approved by other Engineers.

@joe-ayoub-segment
Copy link
Contributor

Hi @nick-Ag I can't deploy this as Validate is failing. Can you take a look please?

@joe-ayoub-segment
Copy link
Contributor

I'll remove the Ready for Release label for now.

@nick-Ag
Copy link
Contributor Author

nick-Ag commented Aug 18, 2025

marking this ready for release pending stratconn review - should be deployed asap

@varadarajan-tw varadarajan-tw requested a review from Copilot August 19, 2025 11:10
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds statistics tracking to Liquid template evaluation by threading a statsContext parameter through the mapping resolution pipeline. The change enables monitoring of Liquid template performance with metrics that include field-specific tags for better observability.

  • Adds statsContext parameter to core mapping functions to enable metric collection
  • Implements timing and success/failure tracking for Liquid template evaluations
  • Enhances metrics with field-level tags to identify which fields trigger template evaluations

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
packages/core/src/mapping-kit/liquid-directive.ts Adds statsContext parameter and timing metrics for Liquid template evaluation
packages/core/src/mapping-kit/index.ts Threads statsContext through mapping resolution pipeline and adds field-level tagging
packages/core/src/destination-kit/index.ts Adds partnerAction tag to statsContext for better metric categorization
packages/core/src/destination-kit/action.ts Passes statsContext to transform functions for batch and single operations


if (statsTagsExist) {
statsContext.tags = originalTags
}
Copy link
Preview

Copilot AI Aug 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The manual tag management creates potential for state corruption if an exception occurs during resolve(). Consider using a try/finally block or creating a scoped statsContext copy to ensure tags are always restored.

Copilot uses AI. Check for mistakes.

} finally {
const duration = Date.now() - start
statsContext?.statsClient?.histogram('liquid.template.evaluation_ms', duration, [
...statsContext.tags,
Copy link
Preview

Copilot AI Aug 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will throw a runtime error if statsContext.tags is undefined. The spread operator should be guarded: ...(statsContext.tags || [])

Suggested change
...statsContext.tags,
...(statsContext?.tags || []),

Copilot uses AI. Check for mistakes.

@joe-ayoub-segment joe-ayoub-segment merged commit f6ba0c4 into main Aug 19, 2025
25 checks passed
@joe-ayoub-segment joe-ayoub-segment deleted the liquid-templates-metrics branch August 19, 2025 11:32
@joe-ayoub-segment
Copy link
Contributor

Hi @nick-Ag PR deployed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants